﻿using System;
using System.Collections;

namespace Program20
{
    class Program
    {
        static void Main(string[] args)
        {
            #region 随机生成数据
            int[] nums = new int[10];
            ArrayList arrayList = new ArrayList();
            Random md = new Random();

            Console.WriteLine("初始化数组");
            while (arrayList.Count < 10)
            {
                int tempNum = md.Next(1, 100);
                if (!arrayList.Contains(tempNum))//判断元素是否存在arrayList中（避免不重复）
                {
                    arrayList.Add(tempNum);
                }
            }
            for (var i = 0; i < nums.Length; i++)
            {
                nums[i] = (int)arrayList[i];
                Console.Write(nums[i] + " ");
            }
            Console.WriteLine();
            #endregion

            int max, min, sum;
            double avg;
            Group(nums, out max, out min, out avg, out sum);
            Console.WriteLine("最大值:",max);
            Console.WriteLine("最小值:",min);
            Console.WriteLine("平均值:",avg);
            Console.WriteLine("总和:",sum);
        }
        //编写一个方法，求出一个数组的最大值，最小值，平均值和总和
        //多个返回值的方法 ouf参数
        //out参数要求在方法的内部必须赋值，并且定义在形参末尾
        public static void Group(int[] nums, out int max,out int min,out double avg,out int sum)
        {
            max = nums[0];
            min = nums[0];
            sum = 0;
            avg = 0;
            for (int i = 0; i < nums.Length; i++)
            {
                if (nums[i] > max)
                    max = nums[i];
                if (nums[i] < min)
                    min = nums[i];
                sum += nums[i];
            }
            avg = (double)(sum / nums.Length);
        }
    }
}
